package com.esyoga.yoyoga.service.impl;

import com.esyoga.yoyoga.mapper.TContractMapper;
import com.esyoga.yoyoga.mapper.TEvaluationMapper;
import com.esyoga.yoyoga.mapper.TOrderMapper;
import com.esyoga.yoyoga.mapper.TTrainerMapper;
import com.esyoga.yoyoga.pojo.*;
import com.esyoga.yoyoga.service.EvaluationSevice;
import com.esyoga.yoyoga.util.PictureInvertUtil;
import lombok.Data;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Data
@Transactional
@Service("evaluationService")
public class EvaluationServiceImpl implements EvaluationSevice {
    @Resource
    TEvaluationMapper evaluationMapper;
    @Resource
    TOrderMapper orderMapper;
    @Resource
    TTrainerMapper trainerMapper;
    @Resource
    TContractMapper contractMapper;
    @Resource
    TEvaluationExample evaluationExample;

    @Override
    public int addEvaluation(TEvaluation evaluation) {
        return evaluationMapper.insertSelective(evaluation);
    }

    @Override
    public TOrder getOrderByOId(int oId) {
        return orderMapper.selectByPrimaryKey(oId);
    }

    @Override
    public TContract getContractByCId(int cId) {
        return contractMapper.selectByPrimaryKey(cId);
    }

    @Override
    public TTrainer getTrainerByTId(int tId) {
        TTrainer trainer = trainerMapper.selectByPrimaryKey(tId);
        //System.out.println(trainer);
        if (trainer.gettImage().length()!=0&&trainer.gettImage()!=null)
            trainer.settImage(PictureInvertUtil.getPathsList(trainer.gettImage()).get(0));
        return trainer;
    }

    @Override
    public List<TEvaluation> getEvaluationByTId(int tId) {
        evaluationExample.clear();
        evaluationExample.createCriteria().andETIdEqualTo(tId);
        return evaluationMapper.selectByExample(evaluationExample);
    }
}
